package edu.towson.cis.cosc490.cero1.lab3;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class ToDoListActivity2 extends Activity implements OnClickListener {
	
	EditText et;
	Button addItem;
	RadioGroup priorities;
	RadioButton high;
	RadioButton med;
	RadioButton low;
	
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_todo_list2);
		initLayout();
	}
	
	public void initLayout(){
		et = (EditText) this.findViewById(R.id.editText1);
		addItem = (Button) this.findViewById(R.id.addItem);
		addItem.setOnClickListener(this);
		priorities = (RadioGroup) this.findViewById(R.id.radioGroup1);
		high = (RadioButton) this.findViewById(R.id.radioHIGH);
		med = (RadioButton) this.findViewById(R.id.radioMEDIUM);
		low = (RadioButton) this.findViewById(R.id.radioLOW);
		//priorities.addView(high);
		//priorities.addView(med);
		//priorities.addView(low);
			
	}

	public void onClick(View v) {
		// when button is clicked take text from et and determine priority, make new ToDoItem
		String message = et.getText().toString();
		ToDoItem item = new ToDoItem(message);
		if(high.isChecked()){
			item.setP(Priority.HIGH);
		} else if(med.isChecked()){
			item.setP(Priority.MEDIUM);
		} else if(low.isChecked()){
			item.setP(Priority.LOW);
		} else{
			//no priority set
			this.setResult(RESULT_CANCELED);
			finish();
		}
		et.setText("");
		
		//set results and return to previous activity
		Intent returnData = getIntent();
		returnData.putExtra("item_str", item);  //returns values of item
		this.setResult(RESULT_OK, returnData);
		finish();
		
	}

}
